<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
<%@page import="support.*, java.util.*, java.sql.*, model.*, data.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="javascript.js" ></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applications</title>
</head>
	


<body>

	<%
	StudentDBModel model = new StudentDBModel();
	Vector<String> reviewers = (Vector<String>)request.getAttribute("reviewers");
	Vector<ReviewerInfo> reviewerInfos = (Vector<ReviewerInfo>)request.getAttribute("reviewerInfos");
	Vector<String> appsInDisc = (Vector<String>)request.getAttribute("appsInDisc");
	Vector<String> appsInSpec = (Vector<String>)request.getAttribute("appsInSpec");
	String reviewer = (String)request.getAttribute("reviewer"); //nullpointer waiting to happen if we aren't called from AppsByReviewer.jsp
	Vector<String> ajaxInfo = (Vector<String>)request.getAttribute("ajaxInfo");
	
	Vector<Application> gradedApps; 
	Vector<Application> unGradedApps;
	

for(int i4 = 0; i4 < reviewerInfos.size(); i4++){
System.err.println("Applications");
System.err.println("reviewerInfos("+i4+") name= "+reviewerInfos.elementAt(i4).getName() );
for(int i5 =0; i5<reviewerInfos.elementAt(i4).getGradedApps().size(); i5++){
System.err.println("gradedApps("+i5+") score= "+reviewerInfos.elementAt(i4).getGradedApps().elementAt(i5).getApplicantName() );
}
for(int i6 =0; i6<reviewerInfos.elementAt(i4).getUnGradedApps().size(); i6++){
System.err.println("gradedApp("+i6+") status= "+reviewerInfos.elementAt(i4).getUnGradedApps().elementAt(i6).getApplicantName() );
}
}	
	
	
System.err.println("(jsp)appsParam: "+(String)request.getAttribute("appsParam"));

	//MAPPING 1
	if( ((String)request.getAttribute("appsParam")).equals("a") ){
		session.setAttribute("appsParam", "a");
		session.setAttribute("reviewer", (String)request.getAttribute("reviewer") );
		
		for(int i=0; i<reviewerInfos.size(); i++){			
			
			if(reviewerInfos.elementAt(i).getName().equals(reviewer)){
				
				gradedApps = reviewerInfos.elementAt(i).getGradedApps();
				
				for(int i2=0; i2 < gradedApps.size(); i2++){%>
					<%=gradedApps.elementAt(i2).getApplicantName()%>
					<%=gradedApps.elementAt(i2).getScore()%>
					<%=gradedApps.elementAt(i2).getStatus()%>
					<%
					if(gradedApps.elementAt(i2).getStatus().equals("[PENDING]") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(a)">							
							Admit<input type="submit" name="button" value="ADMITTED" />
							Reject<input type="submit" name="button" value="REJECTED" />				
						</html:form>								
						<br>					
					<%}
					else if(gradedApps.elementAt(i2).getStatus().equals("ADMITTED") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(a)">						
							Cancel<input type="submit" name="button" value="[PENDING]" />
							Reject<input type="submit" name="button" value="REJECTED" />				
						</html:form>												
					<%}
					else if(gradedApps.elementAt(i2).getStatus().equals("REJECTED") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(a)">							
							Admit<input type="submit" name="button" value="ADMITTED" />
							Cancel<input type="submit" name="button" value="[PENDING]" />										
						</html:form>														
						<br>						
					<%}%>
					
					<%= reviewerInfos.elementAt(i).getGradedApps() %><br>
					<%= reviewerInfos.elementAt(i).getName() %><br>
					<input id="app" type="button" value="Show Application" class="showApplication" alt="<%=(int)gradedApps.elementAt(i2).getStudent_id() %>" />
					<br>	
				<%}
				
			}
		}
	}
				
	//MAPPING 2		
	else if( ((String)request.getAttribute("appsParam")).equals("b") ){
		session.setAttribute("appsParam", "b");
		session.setAttribute("reviewer", (String)request.getAttribute("reviewer") );
		
		for(int i=0; i<reviewerInfos.size(); i++){

			
			if((reviewerInfos.elementAt(i).getName()).equals(reviewer)){
				
				unGradedApps = reviewerInfos.elementAt(i).getUnGradedApps();
				
				for(int i2=0; i2 < unGradedApps.size(); i2++){%>
					<%=unGradedApps.elementAt(i2).getApplicantName()%>
					<%=unGradedApps.elementAt(i2).getScore()%>
					<%=unGradedApps.elementAt(i2).getStatus()%>
					<%
					if(unGradedApps.elementAt(i2).getStatus().equals("[PENDING]") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(b)">							
							Admit<input type="submit" name="button" value="ADMITTED" />
							Reject<input type="submit" name="button" value="REJECTED" />				
						</html:form>																							
					<%}
					else if(unGradedApps.elementAt(i2).getStatus().equals("ADMITTED") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(b)">							
							Cancel<input type="submit" name="button" value="[PENDING]" />
							Reject<input type="submit" name="button" value="REJECTED" />				
						</html:form>																						
					<%}
					else if(unGradedApps.elementAt(i2).getStatus().equals("REJECTED") ){%>
						<html:form method="GET" action="/pages/chairs/GradedVNon(b)">							
							Admit<input type="submit" name="button" value="ADMITTED" />
							Cancel<input type="submit" name="button" value="[PENDING]" />											
						</html:form>													
					<%}%>
					
						<%= reviewerInfos.elementAt(i).getUnGradedApps() %><br>
						<%= reviewerInfos.elementAt(i).getName() %><br>	
										
						<input id="app" type="button" value="Show Application" class="showApplication" alt="<%=(int)unGradedApps.elementAt(i2).getStudent_id() %>" />
					<br>
				<%}
				
			}
		}
	}
	
	//MAPPING 3
	else if(request.getAttribute("appsParam").equals("c") ){
	
		for(int i=0; i<appsInDisc.size(); i++){%>
							
			<%= appsInDisc.get(i)%>	
			<br>			
			<%		
		
		}
		
	}
	
	//MAPPING 4
	else if(request.getAttribute("appsParam").equals("d") ){
		
		for(int i=0; i<appsInSpec.size(); i++){%>
							
			<%= appsInSpec.get(i)%>	
			<br>			
			<%		
		
		}
		
	}
	
	%>

	

	<div id="currentApplication" style="margin: 1em; padding: 1em; border: 1px bashed #000; width: 400px; min-height: 200px;">
	
		No Application loaded.
		
	</div>


	
	
</body>
</html>